﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using QuadRemote.Core;
using System.Collections.Specialized;
using QuadRemote.Tabs;

namespace QuadRemote
{
    public class MainWindow : Form
    {
        private TabControl tabs;
        private TabPage tabConnection;
        private TabPage tabConfig;
        private TabPage tabESC;
        private TabPage tabGraph;
        private TabPage tabDebug;
        private ConnectionPanel connectionPanel1;
        private ESCControl escControl1;
        private ConfigurationPanel configurationPanel1;
        private GraphPanel graphPanel1;
        private Button button1;
        //private UserControl1 userControl11;
        //TopFrame topFrame;
        TabControl tab;

        public MainWindow()
        {
            new FlightSession();

            //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            //this.BackColor = System.Drawing.Color.Black;
            this.ClientSize = new System.Drawing.Size(683, 427);
            this.DoubleBuffered = true;
            //this.Font = new System.Drawing.Font("Calibri", 6F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Name = "MainWindow";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Quad Remote";
            this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainWindow_Unload);
            this.Load += new System.EventHandler(this.MainWindow_Load);
            this.Resize += new System.EventHandler(this.MainWindow_Resize);
            InitializeComponent();

            //new HEXReader("C:\\Users\\Bram\\Desktop\\flightcontroller\\dsESC_Bram.X\\dist\\default\\production\\dsESC_Bram.X.production.hex", HEXReader.FORMAT_PIC33);
        }

        private void MainWindow_Unload(object sender, EventArgs e)
        {
            Bluetooth.instance().stop();
            //GamepadController.instance().stop();
        }

        private void MainWindow_Load(object sender, EventArgs e)
        {
            Bluetooth bt = Bluetooth.instance();
            bt.setParent(this);
            Thread btThread = new Thread(new ThreadStart(bt.run));

            //GamepadController pad = GamepadController.instance();
            //Thread padThread = new Thread(new ThreadStart(pad.run));

            //padThread.Start();
            btThread.Start();

            WindowState = FormWindowState.Maximized;
        }

        private void MainWindow_Resize(object sender, EventArgs e)
        {
            //Console.WriteLine(this.Size.Width + " x " + this.Size.Height);

            //topFrame.Size = new Size(topFrame.Size.Width, this.Size.Height);
            //tab.Size = new Size(this.Size.Width, this.Size.Height);
            //tab.Location = new Point(0, 0);
        }

        private void InitializeComponent()
        {
            this.tabs = new System.Windows.Forms.TabControl();
            this.tabConnection = new System.Windows.Forms.TabPage();
            this.tabConfig = new System.Windows.Forms.TabPage();
            this.tabESC = new System.Windows.Forms.TabPage();
            this.tabGraph = new System.Windows.Forms.TabPage();
            this.tabDebug = new System.Windows.Forms.TabPage();
            this.connectionPanel1 = new QuadRemote.Tabs.ConnectionPanel();
            this.configurationPanel1 = new QuadRemote.Tabs.ConfigurationPanel();
            this.escControl1 = new QuadRemote.Tabs.ESCControl();
            this.graphPanel1 = new QuadRemote.Tabs.GraphPanel();
            this.button1 = new System.Windows.Forms.Button();
            this.tabs.SuspendLayout();
            this.tabConnection.SuspendLayout();
            this.tabConfig.SuspendLayout();
            this.tabESC.SuspendLayout();
            this.tabGraph.SuspendLayout();
            this.tabDebug.SuspendLayout();
            this.SuspendLayout();
            // 
            // tabs
            // 
            this.tabs.Controls.Add(this.tabConnection);
            this.tabs.Controls.Add(this.tabConfig);
            this.tabs.Controls.Add(this.tabESC);
            this.tabs.Controls.Add(this.tabGraph);
            this.tabs.Controls.Add(this.tabDebug);
            this.tabs.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabs.Location = new System.Drawing.Point(0, 0);
            this.tabs.Name = "tabs";
            this.tabs.SelectedIndex = 0;
            this.tabs.Size = new System.Drawing.Size(621, 482);
            this.tabs.SizeMode = System.Windows.Forms.TabSizeMode.FillToRight;
            this.tabs.TabIndex = 0;
            // 
            // tabConnection
            // 
            this.tabConnection.Controls.Add(this.connectionPanel1);
            this.tabConnection.Location = new System.Drawing.Point(4, 22);
            this.tabConnection.Name = "tabConnection";
            this.tabConnection.Padding = new System.Windows.Forms.Padding(3);
            this.tabConnection.Size = new System.Drawing.Size(613, 456);
            this.tabConnection.TabIndex = 1;
            this.tabConnection.Text = "Session";
            this.tabConnection.UseVisualStyleBackColor = true;
            // 
            // tabConfig
            // 
            this.tabConfig.Controls.Add(this.configurationPanel1);
            this.tabConfig.Location = new System.Drawing.Point(4, 22);
            this.tabConfig.Name = "tabConfig";
            this.tabConfig.Size = new System.Drawing.Size(613, 456);
            this.tabConfig.TabIndex = 4;
            this.tabConfig.Text = "Configuration";
            this.tabConfig.UseVisualStyleBackColor = true;
            // 
            // tabESC
            // 
            this.tabESC.Controls.Add(this.escControl1);
            this.tabESC.Location = new System.Drawing.Point(4, 22);
            this.tabESC.Name = "tabESC";
            this.tabESC.Size = new System.Drawing.Size(613, 456);
            this.tabESC.TabIndex = 5;
            this.tabESC.Text = "ESC";
            this.tabESC.UseVisualStyleBackColor = true;
            // 
            // tabGraph
            // 
            this.tabGraph.Controls.Add(this.graphPanel1);
            this.tabGraph.Location = new System.Drawing.Point(4, 22);
            this.tabGraph.Name = "tabGraph";
            this.tabGraph.Size = new System.Drawing.Size(613, 456);
            this.tabGraph.TabIndex = 3;
            this.tabGraph.Text = "Graph";
            this.tabGraph.UseVisualStyleBackColor = true;
            // 
            // tabDebug
            // 
            this.tabDebug.Controls.Add(this.button1);
            this.tabDebug.Location = new System.Drawing.Point(4, 22);
            this.tabDebug.Name = "tabDebug";
            this.tabDebug.Size = new System.Drawing.Size(613, 456);
            this.tabDebug.TabIndex = 6;
            this.tabDebug.Text = "Debug";
            this.tabDebug.UseVisualStyleBackColor = true;
            // 
            // connectionPanel1
            // 
            this.connectionPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.connectionPanel1.Location = new System.Drawing.Point(3, 3);
            this.connectionPanel1.Name = "connectionPanel1";
            this.connectionPanel1.Size = new System.Drawing.Size(607, 450);
            this.connectionPanel1.TabIndex = 0;
            this.connectionPanel1.Load += new System.EventHandler(this.connectionPanel1_Load);
            // 
            // configurationPanel1
            // 
            this.configurationPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.configurationPanel1.Location = new System.Drawing.Point(0, 0);
            this.configurationPanel1.Name = "configurationPanel1";
            this.configurationPanel1.Size = new System.Drawing.Size(613, 456);
            this.configurationPanel1.TabIndex = 0;
            // 
            // escControl1
            // 
            this.escControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.escControl1.Location = new System.Drawing.Point(0, 0);
            this.escControl1.Name = "escControl1";
            this.escControl1.Size = new System.Drawing.Size(613, 456);
            this.escControl1.TabIndex = 0;
            // 
            // graphPanel1
            // 
            this.graphPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.graphPanel1.Location = new System.Drawing.Point(0, 0);
            this.graphPanel1.Name = "graphPanel1";
            this.graphPanel1.Size = new System.Drawing.Size(613, 456);
            this.graphPanel1.TabIndex = 0;
            this.graphPanel1.Load += new System.EventHandler(this.graphPanel1_Load);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(58, 65);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "RC Debug";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // MainWindow
            // 
            this.ClientSize = new System.Drawing.Size(621, 482);
            this.Controls.Add(this.tabs);
            this.Name = "MainWindow";
            this.tabs.ResumeLayout(false);
            this.tabConnection.ResumeLayout(false);
            this.tabConfig.ResumeLayout(false);
            this.tabESC.ResumeLayout(false);
            this.tabGraph.ResumeLayout(false);
            this.tabDebug.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        private void graphPanel1_Load(object sender, EventArgs e)
        {

        }

        private void connectionPanel1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DebugRC rc = new DebugRC();
            rc.Show();
        }
    }
}
